import argparse
import sys

import command
import constants
import maven_cmd


def mvn_deploy_get():
    cmd = maven_cmd.get_command_line()
    parser = argparse.ArgumentParser(description='maven 拉取安装远程jar到本地')
    parser.add_argument('-u', '--url', nargs='?', default='', help='远程地址')
    args, unknown_args = parser.parse_known_args()
    url = args.url
    if len(url.strip()) == 0 and len(unknown_args) > 0:
        url = unknown_args[0]
    if len(url.strip()) == 0:
        print("请输入: 远程地址")
        sys.exit()
    split = url.split("artifact/")
    if len(split) != 2:
        print("请输入: 正确的远程地址")
        sys.exit()
    split_ = split[1].split('/')
    command_line = constants.MAVEN_PULL_REMOTE.format(cmd, url, split_[0], split_[1], split_[2])
    command.exe_command(command_line)


if __name__ == '__main__':
    mvn_deploy_get()
